<?php
    if( ! defined( 'XOOPS_ROOT_PATH' ) ) die("XOOPS_ROOT_PATH not defined!");
    include dirname(__FILE__)."/xoops.php";
	$module_name = basename( dirname(dirname( __FILE__ ))) ;
	include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
	global $xoopsDB,$xoopsModuleConfig,$xoopsModule,$xoopsUser,$return;
	$info_tree = new XoopsTree($xoopsDB->prefix($module_name), "storyid", "parent_id");
	$mod_isAdmin = ($xoopsUser && $xoopsUser->isAdmin()) ? true : false;
	$myts =& MyTextSanitizer::getInstance();
	$infothisgroups = (is_object($xoopsUser)) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
	$infoperm_handler = xoops_gethandler('groupperm');
	$show_info_perm = $infoperm_handler->getItemIds(_CON_INFO_PERMNAME, $infothisgroups, $xoopsModule->getVar('mid'));
	$tueber = ($this->is_new()) ? _INFO_ADDCONTENT : _INFO_EDITCONTENT;
	if ((!in_array(_CON_INFO_CANCREATE,$show_info_perm) && $this->is_new()) || (!in_array(_CON_INFO_CANUPDATE,$show_info_perm) && !$this->is_new())) {
	  if (!$mod_isAdmin) {
		redirect_header(XOOPS_URL, 3, _NOPERM);
	    exit();
	  }
	} 
	$form = new XoopsThemeForm($tueber, $xoopsModule->getVar('dirname')."_form", $_SERVER['SCRIPT_NAME']);
    $form->setExtra('enctype="multipart/form-data"');
	$form->addElement(new XoopsFormHiddenToken());
	$form->addElement(new XoopsFormHidden('storyid', $this->getVar('storyid'))); 
	$form->addElement(new XoopsFormHidden('bakid', $this->getVar('bakid'))); 
	$form->addElement(new XoopsFormHidden('id', $this->getVar('storyid'))); 
	$form->addElement(new XoopsFormHidden('return', $return));
	$form->addElement(new XoopsFormHidden('frontpage', $this->getVar('frontpage'))); 
	if (isset($_GET['cat'])) $this->setVar('homepage',intval($_GET['cat']));
	$form->addElement(new XoopsFormHidden('cat', $this->getVar('homepage')));
	if ((in_array(_CON_INFO_ALLCANUPDATE_CAT,$show_info_perm) && $this->is_new()) || (in_array(_CON_INFO_CANUPDATE_CAT,$show_info_perm) && !$this->is_new()) || $mod_isAdmin) {
	  $block_select = new XoopsFormSelect(_INFO_HOMEPAGE, "homepage",intval($this->getVar('homepage')));
	  $sql="SELECT catid,title FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." ORDER BY title ASC";
	  $result=$xoopsDB->query($sql);
	  $blist=array();
	  if ($result) {
		while($myrow = $xoopsDB->fetcharray($result)) {
		  $blist[$myrow['catid']] =  $myrow['title'];
	    }
	  } 
	  $block_select->addOptionArray($blist);
	  $block_select->setextra('onchange="document.forms.'.$xoopsModule->getVar('dirname')."_form".'.submit()"');
	  $form->addElement($block_select,true);
	} else {
	  $form->addElement(new XoopsFormHidden('homepage', $this->getVar('homepage')));
	}
	
	$form->addElement(new XoopsFormText(_INFO_LINKNAME, "title", 80, 255,$this->getVar('title')),true); 
	$form->addElement(new XoopsFormText(_INFO_TOOLTIP, "tooltip", 80, 255,$this->getVar('tooltip')),false); 
	if ($this->getVar('link') == 0 || $this->getVar('link') == 1 || $this->getVar('link') == 2 || $this->getVar('link') == 4 || $this->getVar('link') == 5) {
	  $title_sicht = new XoopsFormCheckBox(_INFO_TITLESICHT, 'title_sicht',$this->getVar('title_sicht'));
      $title_sicht->addOption(1, _YES);
      $form->addElement($title_sicht);
	} else {
	  $form->addElement(new XoopsFormHidden('title_sicht', $this->getVar('title_sicht')));
	}
	if ($this->getVar('link') == 0 || $this->getVar('link') == 1 || $this->getVar('link') == 2 || $this->getVar('link') == 4 || $this->getVar('link') == 5) {
	  $footer_sicht = new XoopsFormCheckBox(_INFO_FOOTERSICHT, 'footer_sicht',$this->getVar('footer_sicht'));
	  $footer_sicht->addOption(1, _YES);
	  $form->addElement($footer_sicht);
	} else {
	  $form->addElement(new XoopsFormHidden('footer_sicht', $this->getVar('footer_sicht')));
	}
	$cAllList = $info_tree->getAllChild(0,"blockid");
	$menu = array(0=>" ");
	foreach ($cAllList as $tc) {
	  if ($tc['homepage'] == $this->getVar('homepage') && $tc['storyid'] != $this->getVar('storyid')) {
	    $menu[$tc['storyid']] = str_repeat ("&nbsp;&nbsp;", count($info_tree->getAllParentId($tc['storyid']))) . $tc['title'];
	  }
	}
	$categoria_select = new XoopsFormSelect(_INFO_POSITION, "parent_id",intval($this->getVar('parent_id')));
	$categoria_select->addOptionArray($menu);
	unset($menu);
	if ((!in_array(_CON_INFO_ALLCANUPDATE_POSITION,$show_info_perm) && $this->is_new()) || (!in_array(_CON_INFO_CANUPDATE_POSITION,$show_info_perm) && !$this->is_new())) {
	  if (!$mod_isAdmin) $categoria_select->setextra('disabled');	    
	} 
    $form->addElement($categoria_select);
	
	$form->addElement(new XoopsFormText(_INFO_LINKID, "blockid", 5, 5,$this->getVar('blockid')),false); 
	$url_art = new XoopsFormSelect(_INFO_URLART, "link", $this->getVar('link'));
	$url_art->addOption(0, _INFO_URL_NORMAL);
	$url_art->addOption(3, _INFO_URL_KATEGORIE);
	$url_art->addOption(1, _INFO_URL_EXTLINK);
    $url_art->addOption(2, _INFO_URL_INTLINK);
	$url_art->addOption(5, _INFO_URL_IFRAME);
	$url_art->addOption(4, _INFO_URL_INTDATEI);
	
	$url_art->setextra('onchange="document.forms.'.$xoopsModule->getVar('dirname')."_form".'.submit()"');
	if ((!in_array(_CON_INFO_ALLCANUPDATE_SITEART,$show_info_perm) && $this->is_new()) || (!in_array(_CON_INFO_CANUPDATE_SITEART,$show_info_perm) && !$this->is_new())) {
	  if (!$mod_isAdmin) $url_art->setExtra('disabled');
	}
	$form->addElement($url_art,true); 
	
	if ($this->getVar('link') == 1 || $this->getVar('link') == 2 || $this->getVar('link') == 4 || $this->getVar('link') == 5) {
	  switch ($this->getVar('link')) {
		case 1:
			$form->addElement(new XoopsFormText(_INFO_URL_INTERN, "address", 80, 255,$this->getVar('address')),true); 
			break;
		case 2:
			$form->addElement(new XoopsFormText(_INFO_URL_EXTERN, "address", 80, 255,$this->getVar('address')),true); 
			break;
		case 4:
			$form->addElement(new XoopsFormText(_INFO_URL_DATEI, "address", 80, 255,$this->getVar('address')),true); 
			break;
		case 5:
			$iframe=unserialize($this->getVar('frame'));
			$form->addElement(new XoopsFormText(_INFO_URL_FRAME, "address", 80, 255,$this->getVar('address')),true); 
			$form->addElement(new XoopsFormText(_INFO_URL_FRAME_HEIGHT, "iframe_height", 5, 5,$iframe['height']),true); 
			$form->addElement(new XoopsFormText(_INFO_URL_FRAME_BORDER, "iframe_border", 5, 5,$iframe['border']),true);
			$form->addElement(new XoopsFormText(_INFO_URL_FRAME_WIDTH, "iframe_width", 5, 5,$iframe['width']),false);
			$frame_align=new XoopsFormSelect(_INFO_URL_FRAME_ALIGN, "iframe_align", $iframe['align']);
	        $frame_align->addOption('left', _LEFT);
			$frame_align->addOption('center', _CENTER);
			$frame_align->addOption('right', _RIGHT);
		    $form->addElement($frame_align,true);
			break;
		default:
		    $form->addElement(new XoopsFormHidden('address', $this->getVar('address')));
			break;
	  } 
    } else {
		$form->addElement(new XoopsFormHidden('address', $this->getVar('address')));
	}
	if ($this->getVar('link') == 1 || $this->getVar('link') == 2) {
		$menu_selfbox = new XoopsFormCheckBox(_INFO_SELF, 'self',$this->getVar('self'));
	    $menu_selfbox->addOption(1, _YES);
	    $form->addElement($menu_selfbox);
	} else {
		  $form->addElement(new XoopsFormHidden('self', $this->getVar('self')));
	}
	if (intval($this->getVar('link')) == 3) {
		$menu_clickbox = new XoopsFormCheckBox(_INFO_CLICK, 'click',$this->getVar('click'));
	    $menu_clickbox->addOption(1, _YES);
	    $form->addElement($menu_clickbox);
	} else {
		  $form->addElement(new XoopsFormHidden('click', $this->getVar('click'))); 
	}
	$visible_checkbox = new XoopsFormCheckBox(_INFO_VISIBLE, 'visible',$this->getVar('visible'));
	$visible_checkbox->addOption(1, _YES);
	$form->addElement($visible_checkbox);
	if (intval($this->getVar('homepage')) == 1) {
		if (intval($this->getVar('link')) == 3) {
		  $form->addElement(new XoopsFormHidden('submenu', $this->getVar('submenu'))); 
		} else {
		  $menu_checkbox = new XoopsFormCheckBox(_INFO_SUBMENU, 'submenu',$this->getVar('submenu'));
	      $menu_checkbox->addOption(1, _YES);
	      $form->addElement($menu_checkbox);
		}
	} else {
		  $form->addElement(new XoopsFormHidden('submenu', $this->getVar('submenu'))); 
	}
	$sgroup=explode(",",$this->getVar('visible_group'));
	$groups= new XoopsFormSelectGroup(_INFO_VISIBLE_GROUP, 'visible_group', true, $sgroup, 5,true);
	if ((!in_array(_CON_INFO_ALLCANUPDATE_GROUPS,$show_info_perm) && $this->is_new()) || (!in_array(_CON_INFO_CANUPDATE_GROUPS,$show_info_perm) && !$this->is_new())) {
	  if ($mod_isAdmin) {
		    $form->addElement($groups,true);
	  } else {
		    if (!$this->is_new()) {
		      $form->addElement(new XoopsFormHidden('visible_group', $this->getVar('visible_group'))); 
		    } else {
			  $form->addElement(new XoopsFormHidden('visible_group',''));
			}
	  }
	} else {
          $form->addElement($groups,true);
	}
	$form->addElement(new XoopsFormRadioYN(_INFO_VISIBLE_LEFTBLOCK, 'bl_left',$this->getVar('bl_left'), $yes=_YES, $no=_NO));
	$form->addElement(new XoopsFormRadioYN(_INFO_VISIBLE_RIGHTBLOCK, 'bl_right',$this->getVar('bl_right'), $yes=_YES, $no=_NO));
	if ($this->getVar('link') == 0) {
	  global $xoopsModuleConfig,$xoopsConfig,$xoopsModule,$xoopsUser;			
	  $editor_configs=array('name'   => 'message',
							'value'  => $this->getVar('text','n'),
    						'rows'   => 20,
    						'cols'   => 80,
    						'width'  => '99%',
    						'height' => '300px');
	  if (is_readable(XOOPS_ROOT_PATH."/class/xoopseditor/xoopseditor.php") && is_readable(XOOPS_ROOT_PATH."/Frameworks/art/xoopsformloader.php")) { 								
		$editor = (!empty($_POST['editor'])) ? $_POST['editor']:"";
		if ($editor == "") {
		  if(is_object($xoopsUser)) $editor =@ $xoopsUser->getVar("editor"); // Need set through user profile
	      if(empty($editor)) $editor =@ $xoopsConfig["editor_default"];
			  if(empty($editor)) $editor = "dhtmltextarea";
		  }		
		  $dohtml = ($editor=="dhtmltextarea" || $editor=="textarea" || $editor=="dhtmlext") ? 1:0;		
		  if (is_readable(XOOPS_ROOT_PATH."/Frameworks/art/xoopsformloader.php"))
		     include_once XOOPS_ROOT_PATH."/Frameworks/art/xoopsformloader.php";
		  if (empty($xoopsUser)) $dohtml=1; // Gast kein HTML erlauben Risiko!!
		  if (class_exists("XoopsFormEditor")) { 			
			 $edi = new XoopsFormEditor(_DESCRIPTION, $editor, $editor_configs, $dohtml, "dhtmltextarea");
			 @$editor = $edi->editor->editorname;
			 if ($xoopsModuleConfig[$xoopsModule->getVar('dirname').'_editors']==1)
			    $form->addElement(new XoopsFormSelectEditor($form, "editor", $editor));
		     $dohtml = ($editor=="dhtmltextarea" || $editor=="textarea" || $editor=="dhtmlext") ? 1:0;
			 $this->setVar('dohtml',$dohtml);
		  } else {
			  $form->insertBreak(_AM_INFO_NOFRAMEOREDITOR);
			  $edi = new XoopsFormDhtmlTextArea(_DESCRIPTION, $editor_configs['name'], $editor_configs['value'], $editor_configs['rows'], $editor_configs['cols']);
		  }
		} else {
		  $form->insertBreak(_AM_INFO_NOFRAMEOREDITOR);
		  $edi = new XoopsFormDhtmlTextArea(_DESCRIPTION, $editor_configs['name'], $editor_configs['value'], $editor_configs['rows'], $editor_configs['cols']);
		}
		$form->addElement($edi, true);
	  }
	  if (intval($this->getVar('link')) == 0 || intval($this->getVar('link')) == 4 ) {
		$option_tray = new XoopsFormElementTray(_OPTIONS,'<br />');
		if ($xoopsUser && $xoopsUser->isAdmin()) {
		  $nohtml_checkbox = new XoopsFormCheckBox('', 'dohtml',intval($this->getVar('dohtml')));
		  $nohtml_checkbox->addOption(1,_DISABLEHTML);
		  $option_tray->addElement($nohtml_checkbox);
		  $breaks_checkbox = new XoopsFormCheckBox('', 'dobr', intval($this->getVar('dobr')));
	      $breaks_checkbox->addOption(1, _INFO_DISABLEBREAKS);
		  $option_tray->addElement($breaks_checkbox);
	    } else {
		  if (!isset($dohtml)) $dohtml=1; 
		  if (!isset($dobr)) $dobr=0; 
		  $form->addElement(new XoopsFormHidden('dobr', intval($dobr)));
		  $form->addElement(new XoopsFormHidden('dohtml', intval($dohtml)));	
		}
	   
	    $smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', intval($this->getVar('nosmiley')));
	    $smiley_checkbox->addOption(1, _DISABLESMILEY);
	    $option_tray->addElement($smiley_checkbox);
	    $comments_checkbox = new XoopsFormCheckBox('', 'nocomments', intval($this->getVar('nocomments')));
	    $comments_checkbox->addOption(1, _INFO_DISABLECOM);
	    $option_tray->addElement($comments_checkbox);
	    $form->addElement($option_tray);
	 } else {
		$form->addElement(new XoopsFormHidden('message', $this->getVar('text','n')));
		$form->addElement(new XoopsFormHidden('nohtml', $this->getVar('dohtml'))); 
		$form->addElement(new XoopsFormHidden('nosmiley', $this->getVar('nosmiley')));  
		$form->addElement(new XoopsFormHidden('nobreaks', $this->getVar('nobreaks'))); 
		$form->addElement(new XoopsFormHidden('nocomments', $this->getVar('nocomments'))); 
	 }
		$member_handler =& xoops_gethandler('member');
        $thisUser =& $member_handler->getUser($this->getVar('edited_user'));
		if ($this->getVar('owner')==-1) {
		  if ($xoopsUser) $this->setVar('owner',$xoopsUser->uid());
			 else $this->setVar('owner',0);
		} 
		$thisUser2 =& $member_handler->getUser($this->getVar('owner'));
		if ($op!="app_edit") {
		  if (is_object($thisUser2)) {
			  if ($thisUser2->uname() != "") $owner = $thisUser2->uname();
				  else $owner = ($xoopsUser) ? $xoopsUser->getVar('uname'):_MI_INFO_GUEST;
			}	else $owner = _MI_INFO_GUEST;
		} else {
		  if (is_object($thisUser2)) {
			  if ($thisUser2->uname() != "") $owner = $thisUser2->uname();
				  else $owner = _MI_INFO_GUEST;
			} else $owner = _MI_INFO_GUEST;
		}
		$ownerid = (is_object($thisUser2) && ($thisUser2->uname()!="")) ? $thisUser2->uid() : 0;
		$form->addElement(new XoopsFormHidden('owner', $ownerid)); 
		$form->addElement(new XoopsFormLabel(_INFO_OWNER, $owner));	
		if (is_object($thisUser)) {
		  if ($thisUser->uname() != "") $last_editor = $thisUser->uname();
			  else $last_editor = ($xoopsUser) ? $xoopsUser->getVar('uname'):_MI_INFO_GUEST;
		} else {
		  $last_editor = ($xoopsUser) ? $xoopsUser->getVar('uname'):_MI_INFO_GUEST;
		}
		$last_time = ($this->getVar('edited_time')>0) ? date(_DATESTRING,$this->getVar('edited_time')) : date(_DATESTRING);
		$form->addElement(new XoopsFormLabel(_INFO_LAST_EDITED, sprintf(_INFO_LAST_EDITEDTEXT,$last_editor,$last_time)));
		if (in_array(81,$show_info_perm) || $mod_isAdmin) {
			$statusform = new XoopsFormRadio(_INFO_FREIGABEART, "st",$this->getVar('st'));
			$statusform->addOption(1,_INFO_FREIGABEART_YES);
			$statusform->addOption(2,_INFO_FREIGABEART_NO);
			$form->addElement($statusform,true);
		} else {
		  $this->setVar('st',0);
		  if ($this->is_new()) {
			if ($xoopsUser && $xoopsUser->uid()==$ownerid) 
		      if (in_array(_CON_INFO_ALLCANUPDATE_SITEFULL,$show_info_perm)) $this->setVar('st',1);
		  } else {
		    if ($xoopsUser && $xoopsUser->uid()==$ownerid) 
		      if (in_array(_CON_INFO_CANUPDATE_SITEFULL,$show_info_perm)) $this->setVar('st',1);
		  }
		}
		if (is_readable(XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php")) {
		  include_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php";
		  $xcaptcha = new XoopsFormCaptcha('', 'xoopscaptcha', true, 5, 10, 10, 0, 1);
		  $form->addElement($xcaptcha,true);
		}
	    $form->addElement(new XoopsFormHidden('op', 'save'));
		$submit = new XoopsFormElementTray("", "");
		$submit->addElement(new XoopsFormButton('', 'post', $tueber, 'submit'));
		$cancelbutton = new XoopsFormButton('', 'button', _CANCEL, 'button');
		$cancelbutton->setExtra("onclick=top.window.location='".XOOPS_URL."/modules/".$xoopsModule->dirname()."/index.php'");
		$submit->addElement($cancelbutton);
        $form->addElement($submit,false);
	    $form->display();
?>